"""create base table

Revision ID: 855c0783226b
Revises: 
Create Date: 2024-09-10 16:23:12.957326

"""
from typing import Sequence, Union
from sqlalchemy.dialects import mysql
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '855c0783226b'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # 创建菜单表
    op.create_table('sys_menu',
        sa.Column('menu_type', mysql.ENUM('MENU', 'IFRAME', 'EXTERNAL_LINK', 'BUTTON'), nullable=False),
        sa.Column('parent_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('title', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=False),
        sa.Column('name', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=False),
        sa.Column('path', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=False),
        sa.Column('component', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('rank', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('redirect', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('icon', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('extra_icon', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('enter_transition', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('leave_transition', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('active_path', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('auths', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('frame_src', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('frame_loading', mysql.ENUM('ENABLED', 'DISABLED'), nullable=False),
        sa.Column('keep_alive', mysql.ENUM('CACHE', 'NO_CACHE'), nullable=False),
        sa.Column('hidden_tag', mysql.ENUM('ALLOW', 'FORBID'), nullable=False),
        sa.Column('fixed_tag', mysql.ENUM('FIXED', 'NOT_FIXED'), nullable=False),
        sa.Column('show_link', mysql.ENUM('SHOW', 'HIDE'), nullable=False),
        sa.Column('show_parent', mysql.ENUM('SHOW', 'HIDE'), nullable=False),
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('updatetime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('higher_menu_options', mysql.JSON(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB',
        mysql_row_format='DYNAMIC'
    )

    # 创建部门表
    op.create_table('sys_department',
        sa.Column('parentId', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('name', mysql.VARCHAR(length=30), nullable=True),
        sa.Column('phone', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('principal', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('email', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('type', mysql.ENUM('company', 'branch', 'departments'), nullable=False),
        sa.Column('status', mysql.ENUM('NORMAL', 'ABNORMAL'), nullable=False),
        sa.Column('remark', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('updatetime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('weight', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['parentId'], ['sys_department.id'], name='department_ibfk_1'),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )
    op.create_index('ix_sys_department_type', 'sys_department', ['type'], unique=False)
    op.create_index('ix_sys_department_status', 'sys_department', ['status'], unique=False)
    op.create_index('ix_sys_department_parentId', 'sys_department', ['parentId'], unique=False)

    # 创建管理员表
    op.create_table('sys_admin',
        sa.Column('nickName', mysql.VARCHAR(length=30), nullable=True),
        sa.Column('userName', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('password', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('avatar', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('mobile', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('email', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('sex', mysql.ENUM('MAN', 'WUMEN'), nullable=False),
        sa.Column('status', mysql.ENUM('NORMAL', 'ABNORMAL'), nullable=False),
        sa.Column('remark', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('updatetime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('logintime', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('loginip', mysql.VARCHAR(length=30), nullable=True),
        sa.Column('department_id', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.ForeignKeyConstraint(['department_id'], ['sys_department.id'], name='admin_ibfk_1'),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )
    op.create_index('userName', 'sys_admin', ['userName'], unique=False)
    op.create_index('ix_sys_admin_status', 'sys_admin', ['status'], unique=False)
    op.create_index('ix_sys_admin_sex', 'sys_admin', ['sex'], unique=False)

    # 创建角色表
    op.create_table('sys_role',
        sa.Column('name', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('code', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('remark', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('status', mysql.ENUM('NORMAL', 'ABNORMAL'), nullable=False),
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('parent_id', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('updatetime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )
    op.create_index('ix_sys_role_status', 'sys_role', ['status'], unique=False)

    # 创建管理员角色关联表
    op.create_table('sys_admin_role_link',
        sa.Column('admin_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('role_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['admin_id'], ['sys_admin.id'], name='admin_role_link_ibfk_1'),
        sa.ForeignKeyConstraint(['role_id'], ['sys_role.id'], name='admin_role_link_ibfk_2'),
        sa.PrimaryKeyConstraint('admin_id', 'role_id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )
    
    # 创建管理员登录记录表
    op.create_table('sys_admin_login_record',
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('admin_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('admin_name', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('ip', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('useragent', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('status', mysql.ENUM('ABNORMAL', 'NORMAL'), nullable=False),
        sa.Column('channels', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('desc', mysql.TEXT(), nullable=False),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['admin_id'], ['sys_admin.id'], name='admin_login_record_ibfk_1'),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )
    op.create_index('ix_sys_admin_login_record_status', 'sys_admin_login_record', ['status'], unique=False)
    
    # 创建管理员操作记录表
    op.create_table('sys_admin_record',
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('updatetime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('admin_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('username', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('action', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('auth', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('path', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('ip_address', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('os', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('browser', mysql.VARCHAR(length=30), nullable=False),
        sa.Column('message', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=False),
        sa.ForeignKeyConstraint(['admin_id'], ['sys_admin.id'], name='admin_record_ibfk_1'),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    # 创建角色菜单关联表    
    op.create_table('sys_role_menu_link',
        sa.Column('role_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('menu_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['menu_id'], ['sys_menu.id'], name='role_menu_link_ibfk_2'),
        sa.ForeignKeyConstraint(['role_id'], ['sys_role.id'], name='role_menu_link_ibfk_1'),
        sa.PrimaryKeyConstraint('role_id', 'menu_id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    # 创建附件表
    op.create_table('sys_attachment',
        sa.Column('category', sa.String(length=255), nullable=False),
        sa.Column('admin_id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('url', sa.String(length=255), nullable=False),
        sa.Column('imagewidth', sa.String(length=255), nullable=False),
        sa.Column('imageheight', sa.String(length=255), nullable=False),
        sa.Column('imagetype', sa.String(length=255), nullable=False),
        sa.Column('imageframes', sa.Integer(), nullable=False),
        sa.Column('filename', sa.String(length=255), nullable=False),
        sa.Column('filesize', sa.Integer(), nullable=False),
        sa.Column('mimetype', sa.String(length=255), nullable=False),
        sa.Column('extparam', sa.String(length=255), nullable=False),
        sa.Column('createtime', sa.Integer(), nullable=False),
        sa.Column('updatetime', sa.Integer(), nullable=False),
        sa.Column('uploadtime', sa.Integer(), nullable=False),
        sa.Column('storage', sa.String(length=255), nullable=False),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    # 创建任务表 
    op.create_table('sys_task_job',
        sa.Column('id', mysql.VARCHAR(length=100), nullable=False),
        sa.Column('admin_id', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.Column('type', mysql.ENUM('SHHSCRIPT', 'HTTP'), nullable=False),
        sa.Column('name', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('triggerType', mysql.ENUM('EVERYDAY', 'EVERYWEEK', 'EVERY2WEEK', 'EVERYMONTH', 'INTERVAL', 'INTERVALMINUTE', 'INTERVALHOUR'), nullable=False),
        sa.Column('month', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('day', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('hour', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('minute', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('second', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('status', sa.Enum('NORMAL', 'ABNORMAL', nullable=False), nullable=False),
        sa.Column('role', mysql.VARCHAR(length=100), nullable=True),
        sa.Column('content', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('url', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('url_agent', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('lastRunTime', mysql.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    # 创建任务记录表
    op.create_table('sys_task_job_record',
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('job_id', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('job_name', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('status', mysql.ENUM('ABNORMAL', 'NORMAL'), nullable=False),
        sa.Column('message', mysql.VARCHAR(length=255), nullable=False),
        sa.Column('createtime', mysql.INTEGER(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['job_id'], ['sys_task_job.id'], name='task_job_record_ibfk_1'),
        sa.PrimaryKeyConstraint('id'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    # 创建配置表
    op.create_table('sys_config',
        sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column('type', mysql.ENUM('group', 'string', 'text', 'int', 'radio', 'select', 'select_mult', 'bool', 'array', 'datetime', 'date', 'file', 'files'), nullable=True),
        sa.Column('title', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=60), nullable=True),
        sa.Column('value', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=512), nullable=True),
        sa.Column('options', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=512), nullable=True),
        sa.Column('description', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=255), nullable=True),
        sa.Column('weigh', mysql.INTEGER(), nullable=True),
        sa.Column('store_range', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=512), nullable=True),
        sa.Column('rule', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=60), nullable=True),
        sa.Column('code', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=100), nullable=False),
        sa.Column('parent_code', mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_0900_ai_ci', length=60), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('code'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB',
        mysql_row_format='DYNAMIC'
    )

    # CREATE sys_sms TABLE 
    op.create_table('sys_sms',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('createtime', sa.Integer(), nullable=False),
        sa.Column('updatetime', sa.Integer(), nullable=False),
        sa.Column('event', sa.Enum('LOGIN', 'REGISTER', 'FORGET', 'UPDATE', name='sys_sms_event'), nullable=False),
        sa.Column('mobile', sa.String(length=30), nullable=False),
        sa.Column('code', sa.String(length=20), nullable=False),
        sa.Column('times', sa.Integer(), nullable=False),
        sa.Column('ip', sa.String(length=100), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.Index('ix_sys_sms_event', 'event'),
        sa.Index('ix_sys_sms_mobile', 'mobile'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    op.create_table('game_user_rule',
        sa.Column('menu_type', sa.Enum('MENU', 'BUTTON', name='game_user_rule_menu_type'), nullable=False),
        sa.Column('parent_id', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(length=100), nullable=False),
        sa.Column('name', sa.String(length=100), nullable=False),
        sa.Column('path', sa.String(length=255), nullable=False),
        sa.Column('component', sa.String(length=255), nullable=True),
        sa.Column('rank', sa.Integer(), nullable=False),
        sa.Column('redirect', sa.String(length=255), nullable=True),
        sa.Column('icon', sa.String(length=255), nullable=True),
        sa.Column('extra_icon', sa.String(length=255), nullable=True),
        sa.Column('enter_transition', sa.String(length=255), nullable=True),
        sa.Column('leave_transition', sa.String(length=255), nullable=True),
        sa.Column('active_path', sa.String(length=255), nullable=True),
        sa.Column('auths', sa.String(length=100), nullable=True),
        sa.Column('frame_src', sa.String(length=255), nullable=True),
        sa.Column('frame_loading', sa.Enum('ENABLED', 'DISABLED', name='game_user_rule_frame_loading'), nullable=False),
        sa.Column('keep_alive', sa.Enum('CACHE', 'NO_CACHE', name='game_user_rule_keep_alive'), nullable=False),
        sa.Column('hidden_tag', sa.Enum('ALLOW', 'FORBID', name='game_user_rule_hidden_tag'), nullable=False),
        sa.Column('fixed_tag', sa.Enum('FIXED', 'NOT_FIXED', name='game_user_rule_fixed_tag'), nullable=False),
        sa.Column('show_link', sa.Enum('SHOW', 'HIDE', name='game_user_rule_show_link'), nullable=False),
        sa.Column('show_parent', sa.Enum('SHOW', 'HIDE', name='game_user_rule_show_parent'), nullable=False),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('createtime', sa.Integer(), nullable=False),
        sa.Column('updatetime', sa.Integer(), nullable=False),
        sa.Column('higher_menu_options', sa.JSON(), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.Index('ix_game_user_rule_auths', 'auths'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )


    op.create_table('game_user_group',
        sa.Column('name', sa.String(length=30), nullable=False),
        sa.Column('code', sa.String(length=30), nullable=False),
        sa.Column('remark', sa.String(length=255), nullable=False),
        sa.Column('status', sa.Enum('ABNORMAL', 'NORMAL'), nullable=False),
        sa.Column('parent_id', sa.Integer(), nullable=False),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('createtime', sa.Integer(), nullable=False),
        sa.Column('updatetime', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('code'),
        sa.Index('ix_game_user_group_parent_id', 'parent_id'),
        sa.Index('ix_game_user_group_status', 'status'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    op.create_table(
        'game_user',
        sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
        sa.Column('createtime', sa.Integer, nullable=False),
        sa.Column('updatetime', sa.Integer, nullable=False),
        sa.Column('logintime', sa.Integer, nullable=True, default=None),
        sa.Column('username', sa.String(length=32), nullable=False),
        sa.Column('nickname', sa.String(length=50), nullable=False),
        sa.Column('password', sa.String(length=100), nullable=False),
        sa.Column('email', sa.String(length=100), nullable=False),
        sa.Column('mobile', sa.String(length=255), nullable=False),
        sa.Column('avatar', sa.String(length=255), nullable=False),
        sa.Column('level', sa.Integer, nullable=False),
        sa.Column('gender', sa.Enum('MAN', 'WUMEN', name='gender_enum'), nullable=False),
        sa.Column('birthday', sa.Integer, nullable=True),
        sa.Column('bio', sa.String(length=100), nullable=False),
        sa.Column('money', sa.Float, nullable=False),
        sa.Column('score', sa.Integer, nullable=False),
        sa.Column('status', sa.Enum('ABNORMAL', 'NORMAL', name='status_enum'), nullable=False),
        sa.Column('group_id', sa.Integer, nullable=True, default=None),
        sa.Column('type', sa.Enum('DEFAULT', 'THIRD_PARTY', name='type_enum'), nullable=False),
        sa.Column('successions', sa.Integer, nullable=True, default=None),
        sa.Column('maxsuccessions', sa.Integer, nullable=True, default=None),
        sa.Column('prevtime', sa.Integer, nullable=True, default=None),
        sa.Column('loginip', sa.String(length=50), nullable=True, default=None),
        sa.Column('loginfailure', sa.Integer, nullable=True, default=None),
        sa.Column('joinip', sa.String(length=50), nullable=True, default=None),
        sa.Column('jointime', sa.Integer, nullable=True, default=None),
        mysql_charset='utf8mb4',
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_engine='InnoDB',
    )
    # 创建索引
    op.create_index('ix_game_user_status', 'game_user', ['status'], unique=False)
    op.create_index('ix_game_user_type', 'game_user', ['type'], unique=False)
    op.create_index('ix_game_user_gender', 'game_user', ['gender'], unique=False)
    op.create_index('group_id', 'game_user', ['group_id'], unique=False)
    # 添加外键约束
    op.create_foreign_key(
        'game_user_ibfk_1',  # 约束名
        'game_user',         # 源表
        'game_user_group',   # 目标表
        ['group_id'],        # 源列
        ['id'],              # 目标列
        ondelete='RESTRICT',
        onupdate='RESTRICT'
    )

    op.create_table('game_third_user',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('platform', sa.String(length=255), nullable=False),
        sa.Column('openid', sa.String(length=255), nullable=False),
        sa.Column('unionid', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.Index('ix_game_third_user_openid', 'openid'),
        sa.Index('ix_game_third_user_platform', 'platform'),
        sa.Index('ix_game_third_user_user_id', 'user_id'),
        sa.Index('ix_game_third_user_unionid', 'unionid'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )

    op.create_table('game_group_rule_link',
        sa.Column('group_id', sa.Integer(), nullable=False),
        sa.Column('rule_id', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('group_id', 'rule_id'),
        sa.ForeignKeyConstraint(['group_id'], ['game_user_group.id'], name='game_group_rule_link_ibfk_1'),
        sa.ForeignKeyConstraint(['rule_id'], ['game_user_rule.id'], name='game_group_rule_link_ibfk_2'),
        mysql_collate='utf8mb4_0900_ai_ci',
        mysql_default_charset='utf8mb4',
        mysql_engine='InnoDB'
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # 删除外键约束
    op.drop_constraint('admin_role_link_ibfk_1', 'sys_admin_role_link', type_='foreignkey')
    op.drop_constraint('admin_role_link_ibfk_2', 'sys_admin_role_link', type_='foreignkey')
    op.drop_constraint('admin_login_record_ibfk_1', 'sys_admin_login_record', type_='foreignkey')
    op.drop_constraint('role_menu_link_ibfk_1', 'sys_role_menu_link', type_='foreignkey')
    op.drop_constraint('role_menu_link_ibfk_2', 'sys_role_menu_link', type_='foreignkey')
    op.drop_constraint('department_ibfk_1', 'sys_department', type_='foreignkey')
    op.drop_constraint('admin_ibfk_1', 'sys_admin', type_='foreignkey')
    op.drop_constraint('admin_record_ibfk_1', 'sys_admin_record', type_='foreignkey')
    op.drop_constraint('task_job_record_ibfk_1', 'sys_task_job_record', type_='foreignkey')
    op.drop_constraint('game_user_ibfk_1', 'game_user', type_='foreignkey')
    op.drop_constraint('game_group_rule_link_ibfk_1', 'game_group_rule_link', type_='foreignkey')
    op.drop_constraint('game_group_rule_link_ibfk_2', 'game_group_rule_link', type_='foreignkey')

    # 删除索引
    op.drop_index('ix_sys_department_parentId', table_name='sys_department')
    op.drop_index('ix_sys_department_status', table_name='sys_department')
    op.drop_index('ix_sys_department_type', table_name='sys_department')
    op.drop_index('ix_sys_sms_event', table_name='sys_sms')
    op.drop_index('ix_sys_sms_mobile', table_name='sys_sms')
    op.drop_index('ix_game_user_rule_auths', table_name='game_user_rule')
    op.drop_index('ix_game_user_group_parent_id', table_name='game_user_group')
    op.drop_index('ix_game_user_group_status', table_name='game_user_group')
    op.drop_index('ix_game_user_status', table_name='game_user')
    op.drop_index('ix_game_user_type', table_name='game_user')
    op.drop_index('ix_game_user_gender', table_name='game_user')
    op.drop_index('group_id', table_name='game_user')
    op.drop_index('ix_game_third_user_openid', table_name='game_third_user')
    op.drop_index('ix_game_third_user_platform', table_name='game_third_user')
    op.drop_index('ix_game_third_user_user_id', table_name='game_third_user')
    op.drop_index('ix_game_third_user_unionid', table_name='game_third_user')

    # 删除表
    op.drop_table('sys_role_menu_link')
    op.drop_table('sys_admin_role_link')
    op.drop_table('sys_admin_record')
    op.drop_index('ix_sys_admin_login_record_status', table_name='sys_admin_login_record')
    op.drop_table('sys_admin_login_record')
    op.drop_index('ix_sys_role_status', table_name='sys_role')
    op.drop_table('role')
    op.drop_index('ix_sys_admin_sex', table_name='sys_admin')
    op.drop_index('ix_sys_admin_status', table_name='sys_admin')
    op.drop_index('userName', table_name='sys_admin')
    op.drop_table('sys_admin')
    op.drop_table('sys_attachment')
    op.drop_table('sys_task_job_record')
    op.drop_table('sys_task_job')
    op.drop_table('sys_department')
    op.drop_table('sys_menu')
    op.drop_table('sys_config')
    op.drop_table('sys_sms')
    op.drop_table('game_user_rule')
    op.drop_table('game_user_group')
    op.drop_table('game_user')
    op.drop_table('game_third_user')
    op.drop_table('game_group_rule_link')

    ### end Alembic commands ###
